package com.jzr.medical.db1.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.jzr.medical.common.LayMapper;
import com.jzr.medical.db1.model.TUser;
import com.jzr.medical.db1.vo.*;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
/**
 * <p>
 * 用户数据表 Mapper 接口 abc
 * </p>
 *
 * @author henry
 * @since 2019-07-22
 */
public interface TUserMapper extends LayMapper<TUser, UserVo,Integer> {
    List<Integer> getIdList(@Param(Constants.WRAPPER) Wrapper wrapper);
    List<String> getRoleCodesByUserCode(String userCode);
    List<String> getRoleCodesById(Integer id);

    List<MenuVo> getMenuByUserCode(String userCode);

    List<UserCodeVo> getCodeList();

    @Select("select id from t_user where user_code=#{userCode}")
    Integer getIdByUserCode(String userCode);

    @Select("select password from t_user where user_code=#{userCode}")
    String getPasswordByUserCode(String userCode);

    @Select("select password from t_user where id=#{userId}")
    String getPasswordById(Integer userId);

    @Update("update t_user set password=#{newPsw} where id=#{userId} and password=#{oldPsw}")
    Integer changePsw(Integer userId, String oldPsw, String newPsw);

    List<UserMenuVo> getMenuByUserId(Integer userId);

    UserInfoVo getUserInfoVoById(Integer id);

    UserInfoVo getUserInfoVoByUserCode(String userCode);

    @Select("select distinct d.`code`,d.`name` \n" +
            "from t_user_role_ref ur,t_role_dept_ref rd,t_dept d \n" +
            "where ur.role_id=rd.role_id and rd.dept_id=d.id\n" +
            "and ur.user_id=#{userId} order by d.name")
    List<DeptCodeVo> getDeptList(Integer userId);
}

